package com.salary.system;

import java.time.LocalDate;

public class RegularEmployee extends Employee {
    private static final int REGULAR_HOURS = 176;
    private static final double OVERTIME_RATE = 1.5;
    private double hourlyWage;
    private int workHours;

    public RegularEmployee(String name, String empId, String department, LocalDate hireDate, double hourlyWage, int workHours) {
        super(name, empId, department, hireDate);
        if (hourlyWage <= 0) {
            throw new IllegalParameterException("时薪必须大于0（当前：" + hourlyWage + "）");
        }
        this.hourlyWage = hourlyWage;
        this.workHours = workHours;
    }

    @Override
    public double calculateSalary() throws InvalidWorkHoursException {
        if (workHours < 0 || workHours > 672) {
            throw new InvalidWorkHoursException(
                "工作时长异常：" + workHours + "小时（合法范围：0-672小时/月）"
            );
        }
        int regularHours = Math.min(workHours, REGULAR_HOURS);
        int overtimeHours = Math.max(workHours - REGULAR_HOURS, 0);
        return (regularHours * hourlyWage) + (overtimeHours * hourlyWage * OVERTIME_RATE);
    }
}